package cyou.breathe.blog.api.user.request;

import cn.hutool.core.lang.Validator;
import cyou.breathe.blog.api.user.request.condition.*;
import cyou.breathe.blog.base.request.BaseRequest;
import lombok.*;

/**
 * @author: breathe
 * @createTime: 2025-08-28
 */
@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class UserQueryRequest extends BaseRequest {

    //通过设置一个枚举和switch来选择不同的分支
    public UserQueryCondition userQueryCondition;

    public UserQueryRequest(Long userId) {
        UserIdQueryCondition userIdQueryCondition = new UserIdQueryCondition(userId);
        this.userQueryCondition = userIdQueryCondition;
    }

    public UserQueryRequest(String number) {
        if (Validator.isMobile(number)) {
            UserPhoneQueryCondition userPhoneQueryCondition = new UserPhoneQueryCondition(number);
            this.userQueryCondition = userPhoneQueryCondition;
        } else if (Validator.isEmail(number)) {
            UserEmailQueryCondition userEmailQueryCondition = new UserEmailQueryCondition(number);
            this.userQueryCondition = userEmailQueryCondition;
        }
    }

    public UserQueryRequest(String number, String password) {
        if (Validator.isMobile(number)) {
            UserPhoneAndPasswordQueryCondition userPhoneAndPasswordQueryCondition = new UserPhoneAndPasswordQueryCondition(number, password);
            this.userQueryCondition = userPhoneAndPasswordQueryCondition;
        } else if (Validator.isEmail(number)) {
            UserEmailAndPasswordQueryCondition userEmailAndPasswordQueryCondition = new UserEmailAndPasswordQueryCondition(number, password);
            this.userQueryCondition = userEmailAndPasswordQueryCondition;
        }
    }

}

